package com.haixiaoke.saas.manage.banner.controller;

import java.util.List;

import com.haixiaoke.saas.banner.domain.Banner;
import com.haixiaoke.saas.banner.service.IBannerService;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 广告信息Controller
 *
 * @author xiaolong
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/manage/banner/banner")
public class ManageBannerController extends BaseController {
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询广告信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Banner banner) {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }

    /**
     * 获取广告信息详细信息
     */
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId) {
        return success(bannerService.selectBannerByBannerId(bannerId));
    }

    /**
     * 新增广告信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody Banner banner) {
        banner.setCreateBy(getUsername());
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改广告信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Banner banner) {
        banner.setUpdateBy(getUsername());
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除广告信息
     */
    @DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds) {
        return toAjax(bannerService.deleteBannerByBannerIds(bannerIds));
    }
}
